|
|
|
|
|
|
|
Examples Filename: Combo.frm |
|
|
|
|
|
|
|
|
In this example, you will find a combo box loaded with state codes (see Figure 23.3). |
|
|
|
|
|
|
|
|
Figure 23.3
The Combo Box Tips form. |
|
|
|
|
|
|
|
|
There are two command buttons that each prompt for a state code to find. The first method uses a loop to find a value: |
|
|
|
 |
|
|
|
|
Private Sub StateFind(ByVal strState As String)
Dim intLoop As Integer
Dim intPos As Integer
intPos = -1
For intLoop = 0 To cboStates.ListCount - 1
If cboStates.List(intLoop) = strState Then
intPos = intLoop
intLoop = cboStates.ListCount
End If
Next intLoop
cboStates.ListIndex = intPos
End Sub |
|
|
|
|
|
|
|
|
The StateFind() routine loops through the combo box from 0 to the value of ListCount - 1. As it loops through the values, it compares each value in the List() property with the value passed in as an argument. If it finds a match, it sets the intPos variable to the looping variable. It then drops out of the loop and sets the ListIndex property of the combo box to the value in the intPos variable. If the value is not found, the ListIndex property is set to -1, which causes the combo box have no value selected. |
|
|
|
|
|